package com.hivclassifier.gui;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

public class PredictionsResultScreen extends JFrame {

	private static final long serialVersionUID = -4087930715907200615L;
	private JPanel topPanel;
	
	public PredictionsResultScreen(String[][] classificationMatrix) {
		
		setTitle("Coreceptor predictions");

		topPanel = new JPanel();
		topPanel.setPreferredSize(new Dimension(600, 600));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 0 };
		gridBagLayout.columnWeights = new double[] { 1 };
		gridBagLayout.rowHeights = new int[] { 1 };
		gridBagLayout.rowWeights = new double[] { 1 };
		topPanel.setLayout(gridBagLayout);
		
		SpringLayout springLayout = new SpringLayout();
        
		if (classificationMatrix != null) {
			DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
			centerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
			
			String[] columnNamesTable3 = {"Name", "Class"};
			
			JTable instancesClassificationResult = new JTable(classificationMatrix, columnNamesTable3);
			instancesClassificationResult.setPreferredScrollableViewportSize(new Dimension(500, 70));
			instancesClassificationResult.getColumnModel().getColumn(0).setCellRenderer(centerRenderer);
			instancesClassificationResult.getColumnModel().getColumn(1).setCellRenderer(centerRenderer);
			instancesClassificationResult.setEnabled(false);
			
			JScrollPane scrollPane = new JScrollPane(instancesClassificationResult);
			GridBagConstraints gbc_mScrollPane = new GridBagConstraints();
			gbc_mScrollPane.fill = GridBagConstraints.BOTH;
			gbc_mScrollPane.insets = new Insets(15, 0, 0, 0);
			gbc_mScrollPane.gridx = 0;
			gbc_mScrollPane.gridy = 0;
			gbc_mScrollPane.anchor = GridBagConstraints.WEST;
			springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 5, SpringLayout.SOUTH, topPanel);
	        springLayout.putConstraint(SpringLayout.WEST, scrollPane, 3, SpringLayout.WEST, topPanel);
	        springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -3, SpringLayout.SOUTH, topPanel);
	        springLayout.putConstraint(SpringLayout.EAST, scrollPane, -3, SpringLayout.EAST, topPanel);
	        topPanel.add(scrollPane, gbc_mScrollPane);
		}
		
		add(topPanel);
		pack();
		setLocationRelativeTo(null); // center the window
		setVisible(true);
	}
}
